/**
 * Created by Administrator on 14-5-18.
 */


var Sequelize = require('sequelize')
    , sequelize = new Sequelize('cloudb', 'cloudb', 'cloudb', {
        dialect: "mysql", // or 'sqlite', 'postgres', 'mariadb'
        port:    3306// or 5432 (for postgres)
    })

sequelize
    .authenticate()
    .complete(function(err) {
        if (!!err) {
            console.log('Unable to connect to the database:', err)
        } else {
            console.log('Connection has been established successfully.');

            var User = sequelize.define('User', {
                username: Sequelize.STRING,
                password: Sequelize.STRING
            });

            User
                .find({ where: { username: 'admin',password:'1234' } })
                .complete(function(err, johnDoe) {
                    if (!!err) {
                        console.log('An error occurred while searching for admin:', err)
                    } else if (!johnDoe) {
                        console.log('No user with the username "admin" has been found.')
                    } else {
                        console.log('Hello ' + johnDoe.username + '!')
                        console.log('All attributes of admin:', johnDoe.values)
                    }
                })
        }
    });




/*
var log = require("../lib/log");
var cfg = require('../config');
var url = require('url');
var db = require('../lib/db.js');
var RUtil = require('./dataformatUtil');
var crypto = require('crypto');

var virapinfo = require('../models/virapinfo');
var customerinfo = require('../models/customerinfo');

var async = require('async');
var log= console.log;



virapinfo.selectAPWiFiWithAPMac('',function(error,results){
    if((error)!== null)
    {
        // 数据库异常
        console.log("system fault:errno("+error.errno+")");
        return;
    }
    else
    {
        console.log("else");

        return;
    }
    console.log("end");
    return;
});
return;


return;
async.waterfall([
    function(cb)
    {
        log('1.2.1: ', 'start');
        virapinfo.selectAPWiFiWithAPMac('',function(error,results){cb(error,results); });
    },
    function(results, cb) {
        log('1.2.2: ',JSON.stringify( results));
        customerinfo.selectMac('',function(error,results){cb(error,results); });
    }
], function (error, results) {

        log('1.2 err: ', error); // -> myerr

        log('1.2 result: ', JSON.stringify( results)); // -> undefined
    return;
});


console.log("ssssssssssssssssss");
async.waterfall([
    function(cb) { log('1.2.11: ', 'start'); cb(null, 3); },
    function(n, cb) { log('1.2.22: ', n); cb(null, 3); },
    function(n, cb) { log('1.2.33: ', n); cb(null, 3); },
    function(n, cb) { log('1.2.44: ', n); cb(null, 3); }
], function (err, result) {
    log('1.2 err1: ', err); // -> myerr
    log('1.2 result1: ', result); // -> undefined
});
*/
